<template>
  <el-dialog
    :title="type==='add'?'新增特价关键字':'编辑特价关键字'"
    :visible.sync="dialogVisible"
    width="400px"
    @close="reset"
  >
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="关键字">
        <el-input v-model="keyName" style="width: 200px;" clearable placeholder="请输入" />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="success">保 存</el-button>
    </span>
  </el-dialog>
</template>
<script>
  import { CmsSpecialKeysAddSave } from '@/api'
  export default {
    data() {
      return {
        type: 'add',
        keyName: null,
        keyId: null,
        form: {},
        dialogVisible: false
      }
    },
    methods: {
      open(row) {
        this.dialogVisible = true
        if (row) {
          this.type = 'edit'
          this.keyId = row.keyId
          this.keyName = row.keyName
        }
        // console.log(row)
      },
      async success() {
        if (this.type === 'add') {
          console.log('add')
          await CmsSpecialKeysAddSave({ keyName: this.keyName })
          this.$emit('Refresh')
          this.reset()
        } else {
          console.log('edit')
          await CmsSpecialKeysAddSave({ keyName: this.keyName, keyId: this.keyId })
          this.$emit('Refresh')
          this.reset()
        }
      },
      reset() {
        this.keyId = null
        this.keyName = null
        this.type = 'add'
        this.dialogVisible = false
      }
    }
  }
</script>
